package com.ficus.road.maintain.handler.smartdecision.strategy;

import com.ficus.road.maintain.core.model.smartnew.SmartDecisionExcelVO;
import com.ficus.road.maintain.core.model.smartnew.SmartDecisionResponse;
import com.ficus.road.maintain.handler.smartdecision.enums.SmartDecisionStrategyEnum;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiawen yang
 * @date 2022/7/20 下午4:22
 */
@Component
public class SmartDecisionHighwayInspectionStrategy implements ISmartDecisionStrategy {
    /**
     * 上次大中修时间大于该值的不进入工程项目
     */
    private static final double DEFAULT_OVERHAUL_YEAR = 2020;

    @Override
    public SmartDecisionStrategyEnum getStrategy() {
        return SmartDecisionStrategyEnum.HIGHWAY_INSPECTION;
    }

    @Override
    public SmartDecisionResponse process(List<SmartDecisionExcelVO> params, SmartDecisionResponse response) {
        ArrayList<String> maintainIds = Lists.newArrayList();
        ArrayList<String> projectIds = Lists.newArrayList();
        params.forEach(param -> {
            String level = param.getLevel();
            String character = param.getRoadCharacter();
            Double pciClassify = param.getPCI();
            Double rqiClassify = param.getRQI();
            Double rdiClassify = param.getRDI();
            if (ObjectUtils.isEmpty(param.getRoadCharacter()) || ObjectUtils.isEmpty(level)) {
                // 数据不全, 暂时放入日常养护
                maintainIds.add(param.getId());
                return;
            }
            if (character.contains("沥青")) {
                try {
                    if ((level.contains("高速公路") && pciClassify >= 80 && rqiClassify >= 80 && rdiClassify >= 80) ||
                            (level.contains("一级") && pciClassify >= 80 && rqiClassify >= 80 && rdiClassify >= 75) ||
                            (level.contains("二级干") && pciClassify >= 75 && rqiClassify >= 80 && rdiClassify >= 70) ||
                            (level.contains("二级非") && pciClassify >= 75 && rqiClassify >= 75 && rdiClassify >= 70) ||
                            ((level.contains("三级") || level.contains("四级")) && pciClassify >= 70 && rqiClassify >= 70)) {
                        // 日常养护
                        maintainIds.add(param.getId());
                    } else {
                        // 工程项目
                        projectIds.add(param.getId());
                    }
                }catch (Exception e){
                    projectIds.add(param.getId());
                }
            }
            if (character.contains("水泥")) {
                try {
                    if (((level.contains("高速") || level.contains("一级")) && pciClassify >= 80 && rqiClassify >= 80) ||
                            (level.contains("二级干") && pciClassify >= 80 && rqiClassify >= 80) ||
                            (level.contains("二级非") && pciClassify >= 80 && rqiClassify >= 75) ||
                            ((level.contains("三级") || level.contains("四级")) && pciClassify >= 70 && rqiClassify >= 70)) {
                        // 日常养护
                        maintainIds.add(param.getId());
                    } else {
                        // 工程项目
                        projectIds.add(param.getId());
                    }
                }catch (Exception e){
                    projectIds.add(param.getId());
                }
            }
        });
        response.getSmartInspectionResponse().setMaintainIds(maintainIds);
        response.getSmartInspectionResponse().setProjectIds(projectIds);
        System.out.println("SmartInspection's projectIds: " + projectIds);
        return response;
    }

//    private boolean isMaintain(SmartDecisionExcelVO param) {
//
//    }
//
//    private boolean isProject(SmartDecisionExcelVO param) {
//
//    }
}
